window.remote = require('electron').remote

const ipcRenderer = require('electron').ipcRenderer

const config = remote.require('./lib/config')

const BrowserWindow = remote.require('electron').BrowserWindow;

const webview = $("#habitica")[0]

$(webview).attr("src",config.get("habitica.homePageURL",'https://habitica.com/'));

const mainWindowsId = ipcRenderer.sendSync('getMainWindowsId', {});

const Bwindow = BrowserWindow.fromId(mainWindowsId)

Bwindow.on('blur',function () {
    $("body").addClass("window-blur");
    console.log("失去焦点");
});

Bwindow.on('focus',function () {
    $("body").removeClass("window-blur");
    console.log("获得焦点");
});

webview.addEventListener('page-title-updated', (e) => {
    document.title = e.title;
    $("#title").text(e.title);
});
webview.addEventListener('new-window', (e) => {
    webview.loadURL(e.url);
});
webview.addEventListener('console-message', (e) => {
  console.log('Guest page logged a message:', e.message)
})


$('.icon-minus').click(function(){
    Bwindow.minimize();
})

function menuCtrl(){}

menuCtrl.menu = $('#menu')[0];

menuCtrl.toggle = function (){
    $(this.menu).toggleClass("reset-transform");
}

menuCtrl.close = function(){
    $(this.menu).removeClass("reset-transform");
}

$('#menu-bottom').click(function(){
    menuCtrl.toggle()
})

// $('#menu').click(function(){
//     $('.page').removeClass('active')
//     $("#" + $(event.target).attr('data-page-id')).addClass('active');
//     console.log(event.target);
// })

$('.nav-fixed-left [back-to-main]').click(function(){
    $('.main-page').addClass('active')
})

function menuEvent(){
    $('.page').removeClass('active')
    $("#" + $(event.currentTarget).attr('data-page-id')).addClass('active');
}